﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Caching;

namespace yinyue
{
   public class HuanCun
    {
       public void HttpDownloadFile(string url, string path,string id)
       {
           // 设置参数
           HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

           //发送请求并获取相应回应数据
           HttpWebResponse response = request.GetResponse() as HttpWebResponse;
           //直到request.GetResponse()程序才开始向目标网页发送Post请求
           Stream responseStream = response.GetResponseStream();
           //创建本地文件写入流
           Directory.CreateDirectory("D:\\音乐\\"+id); 
           Stream stream = new FileStream(path, FileMode.Create);
           byte[] bArr = new byte[1024];
           int size = responseStream.Read(bArr, 0, (int)bArr.Length);
           while (size > 0)
           {
               stream.Write(bArr, 0, size);
               size = responseStream.Read(bArr, 0, (int)bArr.Length);
           }
           stream.Close();
           responseStream.Close();
       }
       public bool Orexist(string Path) {
           if (File.Exists(Path)){
               return true;
           }
           else
           {
               return false;
           }
       }
       public void XinXi(Songlist song,string path) 
       {
           if (!File.Exists(path))
           {
               FileInfo myfile = new FileInfo(path);
               FileStream fs = myfile.Create();
               fs.Close();
           }
           StreamWriter sw = File.AppendText(path);
           sw.WriteLine(song.songname);
           sw.WriteLine(song.seconds);
           sw.WriteLine(song.albummid);
           sw.WriteLine(song.songid);
           sw.WriteLine(song.singerid);
           sw.WriteLine(song.albumpic_big);
           sw.WriteLine(song.albumpic_small);
           sw.WriteLine(song.downUrl);
           sw.WriteLine(song.url);
           sw.WriteLine(song.singername);
           sw.WriteLine(song.albumid);
           sw.Flush();
           sw.Close();
       }

    }   
}
